package com.cw.jeeyt.service.converter.system;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.system.SystemAutoCodeBo;
import com.cw.jeeyt.dao.model.system.SystemAutoCodeDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 自动生成代码转换类
 *
 * @author chenw
 * @date 2019-03-10 13:04:25
 */
public class SystemAutoCodeConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static SystemAutoCodeBo do2Bo(SystemAutoCodeDo model) {
        if (model == null) {
            return null;
        }
        SystemAutoCodeBo bo = new SystemAutoCodeBo();
        bo.setId(model.getId());
        bo.setAbsolutePath(model.getAbsolutePath());
        bo.setPackageName(model.getPackageName());
        bo.setEntityClass(model.getEntityClass());
        bo.setPagePath(model.getPagePath());
        bo.setOutputPagePath(model.getOutputPagePath());
        bo.setTableName(model.getTableName());
        bo.setModuleId(model.getModuleId());
        bo.setPkId(model.getPkId());
        bo.setPkIdCnName(model.getPkIdCnName());
        bo.setTableCnName(model.getTableCnName());
        bo.setTemplateJavaPath(model.getTemplateJavaPath());
        bo.setTemplatePagePath(model.getTemplatePagePath());
        bo.setAuthorName(model.getAuthorName());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        bo.setPkIdUp(model.getPkIdUp());
        bo.setPkIdClass(model.getPkIdClass());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static SystemAutoCodeDo bo2Do(SystemAutoCodeBo bo) {
        if (bo == null) {
            return null;
        }
        SystemAutoCodeDo model = new SystemAutoCodeDo();
        model.setId(bo.getId());
        model.setAbsolutePath(bo.getAbsolutePath());
        model.setPackageName(bo.getPackageName());
        model.setEntityClass(bo.getEntityClass());
        model.setPagePath(bo.getPagePath());
        model.setOutputPagePath(bo.getOutputPagePath());
        model.setTableName(bo.getTableName());
        model.setModuleId(bo.getModuleId());
        model.setPkId(bo.getPkId());
        model.setPkIdCnName(bo.getPkIdCnName());
        model.setTableCnName(bo.getTableCnName());
        model.setTemplateJavaPath(bo.getTemplateJavaPath());
        model.setTemplatePagePath(bo.getTemplatePagePath());
        model.setAuthorName(bo.getAuthorName());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        model.setPkIdUp(bo.getPkIdUp());
        model.setPkIdClass(bo.getPkIdClass());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<SystemAutoCodeBo> doList2BoList(List<SystemAutoCodeDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), SystemAutoCodeConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<SystemAutoCodeDo> boList2DoList(List<SystemAutoCodeBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), SystemAutoCodeConverter::bo2Do));
    }
}